import god from "../../god";
import { face_prop_item } from "../../shared/interface";
import { MsgAction, template, Tpl_propDefault_look, Tpl_skillInfo } from "../../shared/master/MsgAction";
import { player, wallet_key } from "../fight/body/player";
import { SKILL } from "../fight/skill/SK_active";
import { prop_base } from "./prop_base";

export class prop_SkillBook extends prop_base {
    data: SKILL;
    icon: string = '📘';
    constructor(data: face_prop_item) {
        super(data);
        this.data = data.data;
    }
    getStrName(): string {
        return this.data.rename
    }
    use(tag: player, num: number): boolean {
        let skList = tag.getSkill_body()
        
        const skCont = god.getServerCfgItem('skill_cont').b;
        if(skList.length > skCont){
            tag.sendMsg(template.default, `自主学习技能上限为${skCont}个`)
            return false;
        }
        this.num = 0;
        if (this.data instanceof SKILL) {
            tag.addSkill(this.data);
        } else {
            tag.addSkill(new SKILL(this.data));
        }
        tag.sendMsg(template.default, `技能书:${this.data.rename}学习成功`);
        return true;
    }
    look(tag: player) {
        if (!(this.data instanceof SKILL)) {
            this.data = new SKILL(this.data)
        }
        let tpl: Tpl_skillInfo = this.data.get_panel(tag)
        return { template: template.skill_info, data: tpl }
    }
}